﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.RestaurantTable
{
    public class RestaurantTablePresenter : Presenter<IRestaurantTableView>
    {
        public RestaurantTablePresenter(IRestaurantTableView view)
            : base(view)
        {
        }

        public void Display(string restaurantTableId)
        {
            if (restaurantTableId == null) return;

            var restaurantArea = Model.GetRestaurantTable(restaurantTableId);

            View.RestaurantTableID = restaurantArea.RestaurantTableID;
            View.RestaurantTableCode = restaurantArea.RestaurantTableCode;
            View.RestaurantTableName = restaurantArea.RestaurantTableName;
            View.RestaurantAreaID = restaurantArea.RestaurantAreaID;
            View.RestaurantID = restaurantArea.RestaurantID;
            View.MaxPeople = restaurantArea.MaxPeople;
            View.IsOrder = restaurantArea.IsOrder;
            View.IsOrderOnline = restaurantArea.IsOrderOnline;
            View.Description = restaurantArea.Description;
            View.IsActive = restaurantArea.IsActive;
        }

        public int Save()
        {
            var restaurantTable = new RestaurantTableModel
            {
                RestaurantTableID = View.RestaurantTableID,
                RestaurantTableCode = View.RestaurantTableCode,
                RestaurantTableName = View.RestaurantTableName,
                RestaurantAreaID = View.RestaurantAreaID,
                RestaurantID = View.RestaurantID,
                MaxPeople = View.MaxPeople,
                IsOrder = View.IsOrder,
                IsOrderOnline = View.IsOrderOnline,
                Description = View.Description,
                IsActive = View.IsActive
            };

            if (View.RestaurantTableID == null)
                return Model.AddRestaurantTable(restaurantTable);
            else
                return Model.UpdateRestaurantTable(restaurantTable);
        }

        public int Delete(string restaurantTableId)
        {
            return Model.DeleteRestaurantTable(restaurantTableId);
        }
    }
}
